* eliminate some time_t uses.
* whittle down time_t
* move some gpi time handling to Qt.
* drop include comment on defs.h
extern global_options global_opts;
extern const char gpsbabel_version[];
-extern time_t gpsbabel_now; /* gpsbabel startup-time; initialized in main.c with time() */
extern time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! ZERO within testo ! */
enum fix_type {
#include "garmin_gpi.h"
#include <QByteArray> // for QByteArray, operator==
+#include <QDateTime> // for QDateTime
#include <QList> // for QList
#include <QString> // for QString, operator+, operator<
#include <QThread> // for QThread
#include <cstdint> // for uint32_t, int32_t
#include <cstdio> // for SEEK_CUR, SEEK_SET
#include <cstring> // for strlen, strncmp
-#include <ctime> // for time, gmtime, time_t, tm
+#include <ctime> // for time, time_t
#include <memory> // for unique_ptr
-#include "defs.h" // for Waypoint, fatal, le_write32, le_write16, wp_flags, warning, bounds, KPH_TO_MPS, MPH_TO_MPS, WAYPT_HAS, gpsbabel_testmode, parse_speed, WAYPT_SET, MILES_TO_METERS, MPS_TO_KPH, MPS_TO_MPH, mkgmtime, mkshort, mkshort_del_handle, mkshort_new_...
+#include "defs.h"
#include "formspec.h" // for FormatSpecificDataList
#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_alloc
#include "gbfile.h" // for gbfputint32, gbfgetint32, gbfgetint16, gbfputint16, gbfgetc, gbfputc, gbfread, gbftell, gbfwrite, gbfseek, gbfclose, gbfopen_le, gbfgetuint16, gbsize_t, gbfile
PP;
rdata->crdate = gbfgetint32(fin);
if (GPI_DBG) {
- char stime[32];
- struct tm tm = *localtime(&rdata->crdate);
- tm.tm_year += 20; /* !!! */
- tm.tm_mday -= 1; /* !!! */
- strftime(stime, sizeof(stime), "%Y/%m/%d %H:%M:%S", &tm);
- warning("crdate = %lu (%s)\n", rdata->crdate, stime);
+ time_t crdate = GPS_Math_Gtime_To_Utime(rdata->crdate);
+ warning("crdate = %lu (%s)\n", rdata->crdate,
+ CSTR(QDateTime::fromSecsSinceEpoch(crdate, Qt::UTC).toString(Qt::ISODate)));
}
(void) gbfgetint16(fin); /* 0 */
time_t time = gpi_timestamp;
if (time != 0) {
- struct tm tm;
- tm = *gmtime(&time);
- tm.tm_year -= 20;
- time = mkgmtime(&tm);
- time += SECONDS_PER_DAY;
+ time = GPS_Math_Utime_To_Gtime(gpi_timestamp);
}
gbfputint32(0, fout);
*/
case tt_cache_log_type:
if ((cdatastr.compare(u"Found it") == 0) &&
- (0 == wpt_tmp->gc_data->last_found.toTime_t())) {
+ (!wpt_tmp->gc_data->last_found.isValid())) {
wpt_tmp->AllocGCData()->last_found = gc_log_date;
}
gc_log_date = QDateTime();
/* note that the elements must appear in the order required by the schema. */
/* also note some of the elements are required. */
- long secs = 0;
+ long long secs = 0;
if (gtc_least_time.isValid() && gtc_most_time.isValid()) {
- secs = gtc_most_time.toTime_t() - gtc_least_time.toTime_t();
+ secs = gtc_least_time.secsTo(gtc_most_time);
}
/* write these in either case, course or activity format */
- gtc_write_xml(0, "<TotalTimeSeconds>%ld</TotalTimeSeconds>\n", secs);
+ gtc_write_xml(0, "<TotalTimeSeconds>%lld</TotalTimeSeconds>\n", secs);
gtc_write_xml(0, "<DistanceMeters>%.2f</DistanceMeters>\n", tdata.distance_meters);
if (gtc_course_flag) { /* course format */
gtc_write_xml(1, "<BeginPosition>\n");
#include <Qt> // for CaseInsensitive
#include <cstdint> // for int32_t
-#include <ctime> // for localtime, time_t
#include "defs.h"
#include "formspec.h" // for FormatSpecificDataList, kFsGpx
XmlTag* root = fs_gpx->tag;
XmlTag* curlog = root->xml_findfirst(u"groundspeak:log");
while (curlog) {
- time_t logtime = 0;
*file_out << " <p class=\"gpsbabellog\">\n";
XmlTag* logpart = curlog->xml_findfirst(u"groundspeak:type");
logpart = curlog->xml_findfirst(u"groundspeak:date");
if (logpart) {
- logtime = xml_parse_time(logpart->cdata).toTime_t();
- struct tm* logtm = localtime(&logtime);
- if (logtm) {
- *file_out << QStringLiteral("<span class=\"gpsbabellogdate\">%1-%2-%3</span><br>\n")
- .arg(logtm->tm_year+1900, 4, 10, QChar('0'))
- .arg(logtm->tm_mon+1, 2, 10, QChar('0'))
- .arg(logtm->tm_mday, 2, 10, QChar('0'));
- }
+ gpsbabel::DateTime logtime = xml_parse_time(logpart->cdata).toLocalTime();
+ *file_out << "<span class=\"gpsbabellogdate\">"
+ << logtime.toString(u"yyyy-MM-dd") << "</span><br>\n";
}
logpart = curlog->xml_findfirst(u"groundspeak:log_wpt");
last_valid_fix = wpt->GetCreationTime();
}
- wpt->icon_descr = kml_get_posn_icon(wpt->GetCreationTime().toTime_t() - last_valid_fix.toTime_t());
+ wpt->icon_descr = kml_get_posn_icon(last_valid_fix.secsTo(wpt->GetCreationTime()));
/* In order to avoid clutter while we're sitting still, don't add
fatal(MYNAME ": relative needs hdop information.\n");
}
// if timestamps exist, distance to interpolated point
- if (wpt1->GetCreationTime() != wpt2->GetCreationTime()) {
- double frac = (double)(wpt3->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()) /
- (wpt2->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t());
+ if (wpt1->GetCreationTime().isValid() &&
+ wpt2->GetCreationTime().isValid() &&
+ wpt3->GetCreationTime().isValid() &&
+ (wpt1->GetCreationTime() != wpt2->GetCreationTime())) {
+ double frac = static_cast<double>(wpt1->GetCreationTime().msecsTo(wpt3->GetCreationTime())) /
+ static_cast<double>(wpt1->GetCreationTime().msecsTo(wpt2->GetCreationTime()));
linepart(wpt1->latitude, wpt1->longitude,
wpt2->latitude, wpt2->longitude,
frac, &reslat, &reslon);
#include "text.h"
-#include <QChar> // for QChar
#include <QIODevice> // for QIODevice, QIODevice::WriteOnly
#include <QString> // for QString, operator!=
#include <QTextStream> // for QTextStream
#include <Qt> // for CaseInsensitive
#include <cstdint> // for int32_t
-#include <ctime> // for localtime, time_t
#include "defs.h"
#include "formspec.h" // for FormatSpecificDataList, kFsGpx
XmlTag* root = fs_gpx->tag;
XmlTag* curlog = root->xml_findfirst(u"groundspeak:log");
while (curlog) {
- time_t logtime = 0;
*file_out << "\n";
XmlTag* logpart = curlog->xml_findfirst(u"groundspeak:type");
logpart = curlog->xml_findfirst(u"groundspeak:date");
if (logpart) {
- logtime = xml_parse_time(logpart->cdata).toTime_t();
- struct tm* logtm = localtime(&logtime);
- if (logtm) {
- *file_out << QStringLiteral("%1-%2-%3\n")
- .arg(logtm->tm_year+1900, 4, 10, QChar('0'))
- .arg(logtm->tm_mon+1, 2, 10, QChar('0'))
- .arg(logtm->tm_mday, 2, 10, QChar('0'));
- }
+ gpsbabel::DateTime logtime = xml_parse_time(logpart->cdata).toLocalTime();
+ *file_out << logtime.toString(u"yyyy-MM-dd") << "\n";
}
logpart = curlog->xml_findfirst(u"groundspeak:log_wpt");